package com.fastdfs.config;

import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
 * Description
 * Author wangxh
 * Date 2020/7/16-3:32 下午
 * Version V1.0
 **/

@Component
public class FastDFSConfig {

    private static final String FAST_DSF_FILE = "fdfs_client.conf";

    @PostConstruct
    public void init() throws IOException, MyException {
        ClientGlobal.initByProperties(FAST_DSF_FILE);
    }

    @Bean
    public TrackerClient trackerClient(){
        return new TrackerClient();
    }

    @Bean
    public TrackerServer trackerServer(TrackerClient trackerClient) throws IOException {
        return trackerClient.getTrackerServer();
    }

    @Bean
    public StorageClient storageClient(TrackerServer trackerServer){
        return new StorageClient(trackerServer);
    }
}
